package com.fashionista;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.*;

/**
 * Class to parse a web page for the current weather
 * 
 * @author Trevor Adelman, Patrick Koperwas, Tong Wu, Shayan Yassami
 * @version for cs48 group project, 3/11/2011
 */

public class getWeather {
	//private String theString = "Testing";
	private String inputLine;
	private String temp, tempc, humidity, wind, weatherCond;
	private float numtemp;
	private String weatherReading;
	public getWeather(){
}
public void setWeather() throws Exception {
	URL sbweather = new URL("http://www.weather.gov/xml/current_obs/KSBA.xml");
	BufferedReader in = new BufferedReader(
			new InputStreamReader(
			sbweather.openStream()));
	
		while ((inputLine = in.readLine()) != null) {

			if (inputLine.contains("temp_f")) {
				temp = (inputLine.substring(9,11));
				numtemp = Float.valueOf(temp.trim()).floatValue();
			}
			
			if(inputLine.contains("temp_c")) {
				tempc = (inputLine.substring(9,11));
				tempc = tempc.replace(".", "");
				
			}
			if(inputLine.contains("humidity")) {
				humidity = (inputLine.substring(20,22));
				humidity = humidity.replace(".", "");
			}
			if(inputLine.contains("wind_mph")) {
				wind = (inputLine.substring(11,14));
			}
			if(inputLine.contains("<weather>")) {
				weatherCond = (inputLine.substring(10));
				weatherCond = weatherCond.replace("</weather>", "");
			}
		}
		in.close();
}

public String returnWeather() {
	return "The Temperature in Santa Baraba is " + numtemp + " " + weatherReading;
}
public String returnDegree() {
	return temp;
}
public String returnCelDegree() {
	return tempc;
}
public String returnHumidity() {
	return humidity;
}
public String returnWind() {
	return wind;
}
public String returnWeatherCond() {
	return weatherCond;
}
public float returnFloatDegree() {
	return numtemp;
}
public float returnTestDegree() {
	return 45;
}
public int returnIntDegree() {
	return (int) numtemp;
}

public String returnClothing(int temp){
	String imReturningThisBitch = "";
	if (temp < 50) {
		imReturningThisBitch = "thick";
	}
	if (temp > 50 && temp < 60) {
		imReturningThisBitch = "medium";
	}
	if (temp > 60 && temp < 70) {
		imReturningThisBitch="light";
	}
	if (temp > 70) {
		imReturningThisBitch="shorts";
	}
	return imReturningThisBitch;
}
}
